package com.example.m_kartupay.constuctor;
import java.io.InputStream;
import java.util.ArrayList;
 

import com.example.m_kartupay.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TransactionHistoryAdapter extends ArrayAdapter<TransactionHistory> {
	ArrayList<TransactionHistory> transactionList;
	  LayoutInflater vi;
	  int Resource;
	  ViewHolder holder;
	  
	  public TransactionHistoryAdapter(Context context, int resource, ArrayList<TransactionHistory> objects) {
	        super(context, resource, objects);
	        Resource = resource;
	        transactionList = objects;
	    }
	  
	  @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
	        // convert view = design
	        View v = convertView;
	        if (v == null) {
	            holder = new ViewHolder();
	            v = vi.inflate(Resource, null);
	            //holder.imageview = (ImageView) v.findViewById(R.id.ivImage);
	            holder.tvInvoice = (TextView) v.findViewById(R.id.invoice);
	            holder.txOrderNo = (TextView) v.findViewById(R.id.order_no);
	            
	            v.setTag(holder);
	        } else {
	            holder = (ViewHolder) v.getTag();
	        }
	        //holder.imageview.setImageResource(R.drawable.ic_launcher);
	        //new DownloadImageTask(holder.imageview).execute(transactionList.get(position).getImage());
	        holder.tvInvoice.setText(transactionList.get(position).getInvoice());
	        holder.txOrderNo.setText(transactionList.get(position).getOrderNo());
	        
	        return v;
	 
	    }
	 
	    static class ViewHolder {
	       // public ImageView imageview;
	        public TextView tvInvoice;
	        public TextView txOrderNo;
	       
	 
	    }
	    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
	        ImageView bmImage;
	 
	        public DownloadImageTask(ImageView bmImage) {
	            this.bmImage = bmImage;
	        }
	        protected Bitmap doInBackground(String... urls) {
	            String urldisplay = urls[0];
	            Bitmap mIcon = null;
	            try {
	                InputStream in = new java.net.URL(urldisplay).openStream();
	                mIcon = BitmapFactory.decodeStream(in);
	            } catch (Exception e) {
	                Log.e("Error", e.getMessage());
	                e.printStackTrace();
	            }
	            return mIcon;
	        }
	 
	        protected void onPostExecute(Bitmap result) {
	            bmImage.setImageBitmap(result);
	        }
	    }
	

}
